home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / bking2.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  319 lines

  1. /***************************************************************************
  2.  
  3.   bking2.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static UINT8 xld1=0;
  13. static UINT8 xld2=0;
  14. static UINT8 xld3=0;
  15. static UINT8 yld1=0;
  16. static UINT8 yld2=0;
  17. static UINT8 yld3=0;
  18. static int msk=0;
  19. static int ball1_pic;
  20. static int ball2_pic;
  21. static int crow_pic;
  22. static int crow_flip;
  23. static int palette_bank;
  24. static int flipscreen;
  25. static int controller;
  26. static int hitclr=0;
  27.  
  28. /***************************************************************************
  29.  
  30.   Convert the color PROMs into a more useable format.
  31.  
  32.   The palette PROM is connected to the RGB output this way:
  33.  
  34.   bit 7 -- 390 ohm resistor  -- BLUE
  35.         -- 220 ohm resistor  -- BLUE
  36.         -- 820 ohm resistor  -- GREEN
  37.         -- 390 ohm resistor  -- GREEN
  38.         -- 220 ohm resistor  -- GREEN
  39.         -- 820 ohm resistor  -- RED
  40.         -- 390 ohm resistor  -- RED
  41.   bit 0 -- 220 ohm resistor  -- RED
  42.  
  43. ***************************************************************************/
  44. void bking2_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  45. {
  46.     int i;
  47.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  48.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  49.  
  50.  
  51.     for (i = 0;i < Machine->drv->total_colors;i++)
  52.     {
  53.         int bit0,bit1,bit2;
  54.  
  55.  
  56.         /* red component */
  57.         bit0 = (*color_prom >> 0) & 0x01;
  58.         bit1 = (*color_prom >> 1) & 0x01;
  59.         bit2 = (*color_prom >> 2) & 0x01;
  60.         *(palette++) = 0x92 * bit0 + 0x46 * bit1 + 0x27 * bit2;
  61.         /* green component */
  62.         bit0 = (*color_prom >> 3) & 0x01;
  63.         bit1 = (*color_prom >> 4) & 0x01;
  64.         bit2 = (*color_prom >> 5) & 0x01;
  65.         *(palette++) = 0x92 * bit0 + 0x46 * bit1 + 0x27 * bit2;
  66.         /* blue component */
  67.         bit0 = (*color_prom >> 6) & 0x01;
  68.         bit1 = (*color_prom >> 7) & 0x01;
  69.         bit2 = 0;
  70.         *(palette++) = 0x92 * bit0 + 0x46 * bit1 + 0x27 * bit2;
  71.  
  72.         color_prom++;
  73.     }
  74.  
  75.     /* color PROM A7-A8 is the palette select */
  76.  
  77.     /* character colors. Image bits go to A0-A2 of the color PROM */
  78.     for (i = 0; i < TOTAL_COLORS(0); i++)
  79.     {
  80.         COLOR(0,i) = ((i << 4) & 0x180) | (i & 0x07);
  81.     }
  82.  
  83.     /* crow colors. Image bits go to A5-A6. */
  84.     for (i = 0; i < TOTAL_COLORS(1); i++)
  85.     {
  86.         COLOR(1,i) = ((i << 5) & 0x180) | ((i & 0x03) << 5);
  87.     }
  88.  
  89.     /* ball colors. Ball 1 image bit goes to A3. Ball 2 to A4. */
  90.     for (i = 0; i < TOTAL_COLORS(2); i++)
  91.     {
  92.         COLOR(2,i) = ((i << 6) & 0x180) | ((i & 0x01) << 3);
  93.         COLOR(3,i) = ((i << 6) & 0x180) | ((i & 0x01) << 4);
  94.     }
  95. }
  96.  
  97. WRITE_HANDLER( bking2_xld1_w )
  98. {
  99.     xld1 = -data;
  100. }
  101.  
  102. WRITE_HANDLER( bking2_yld1_w )
  103. {
  104.     yld1 = -data;
  105. }
  106.  
  107. WRITE_HANDLER( bking2_xld2_w )
  108. {
  109.     xld2 = -data;
  110. }
  111.  
  112. WRITE_HANDLER( bking2_yld2_w )
  113. {
  114.     yld2 = -data;
  115. }
  116.  
  117. WRITE_HANDLER( bking2_xld3_w )
  118. {
  119.     xld3 = -data;
  120. }
  121.  
  122. WRITE_HANDLER( bking2_yld3_w )
  123. {
  124.     yld3 = -data;
  125. }
  126.  
  127. WRITE_HANDLER( bking2_msk_w )
  128. {
  129.     msk = data;
  130. }
  131.  
  132. WRITE_HANDLER( bking2_cont1_w )
  133. {
  134.     /* D0 = COIN LOCK */
  135.     /* D1 =  BALL 5 (Controller selection) */
  136.     /* D2 = VINV (flip screen) */
  137.     /* D3 = Not Connected */
  138.     /* D4-D7 = CROW0-CROW3 (selects crow picture) */
  139.  
  140.     coin_lockout_global_w(0, ~data & 0x01);
  141.  
  142.     if (flipscreen != (data & 0x04))
  143.     {
  144.         flipscreen = data & 0x04;
  145.         memset(dirtybuffer, 1, videoram_size);
  146.     }
  147.  
  148.     controller = data & 0x02;
  149.  
  150.     crow_pic = (data >> 4) & 0x0f;
  151. }
  152.  
  153. WRITE_HANDLER( bking2_cont2_w )
  154. {
  155.     static int last = -1;
  156.  
  157.     /* D0-D2 = BALL10 - BALL12 (Selects player 1 ball picture) */
  158.     /* D3-D5 = BALL20 - BALL22 (Selects player 2 ball picture) */
  159.     /* D6 = HIT1 */
  160.     /* D7 = HIT2 */
  161.  
  162.     ball1_pic = data & 0x07;
  163.     ball2_pic = (data >> 3) & 0x07;
  164.  
  165.     if ((last & 0xc0) != (data & 0xc0))
  166.     {
  167.         //debug_key_pressed = 1;
  168.         last = data;
  169.     }
  170. }
  171.  
  172. WRITE_HANDLER( bking2_cont3_w )
  173. {
  174.     static int sound_disabled = -1;
  175.  
  176.     /* D0 = CROW INV (inverts Crow picture and coordinates) */
  177.     /* D1-D2 = COLOR 0 - COLOR 1 (switches 4 color palettes, global across all graphics) */
  178.     /* D3 = SOUND STOP */
  179.  
  180.     crow_flip = ~data & 0x01;
  181.  
  182.     if (palette_bank != ((data >> 1) & 0x03))
  183.     {
  184.         palette_bank = (data >> 1) & 0x03;
  185.         memset(dirtybuffer, 1, videoram_size);
  186.     }
  187.  
  188.     if (sound_disabled != (data & 0x08))
  189.     {
  190.         sound_disabled = data & 0x08;
  191.         osd_set_mastervolume(sound_disabled ? -32 : 0);
  192.     }
  193. }
  194.  
  195.  
  196. WRITE_HANDLER( bking2_hitclr_w )
  197. {
  198.     hitclr = data;
  199. }
  200.  
  201.  
  202. READ_HANDLER( bking2_input_port_5_r )
  203. {
  204.     return controller ? input_port_7_r(0) : input_port_5_r(0);
  205. }
  206.  
  207. READ_HANDLER( bking2_input_port_6_r )
  208. {
  209.     return controller ? input_port_8_r(0) : input_port_6_r(0);
  210. }
  211.  
  212.  
  213. /* Hack alert.  I don't know how to upper bits work, so I'm just returning
  214.    what the code expects, otherwise the collision detection is skipped */
  215. READ_HANDLER( bking2_pos_r )
  216. {
  217.     unsigned char *RAM = memory_region(REGION_CPU1);
  218.  
  219.     UINT16 pos, x, y;
  220.  
  221.  
  222.     if (hitclr & 0x04)
  223.     {
  224.         x = xld2;
  225.         y = yld2;
  226.     }
  227.     else
  228.     {
  229.         x = xld1;
  230.         y = yld1;
  231.     }
  232.  
  233.     pos = ((y >> 3 << 5) | (x >> 3)) + 2;
  234.  
  235.     switch (offset)
  236.     {
  237.     case 0x00:
  238.         return (pos & 0x0f) << 4;
  239.     case 0x08:
  240.         return (pos & 0xf0);
  241.     case 0x10:
  242.         return ((pos & 0x0300) >> 4) | (RAM[0x804c] & 0xc0);
  243.     default:
  244.         return 0;
  245.     }
  246. }
  247.  
  248. /***************************************************************************
  249.  
  250.   Draw the game screen in the given osd_bitmap.
  251.   Do NOT call osd_update_display() from this function, it will be called by
  252.   the main emulation engine.
  253.  
  254. ***************************************************************************/
  255. void bking2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  256. {
  257.     int offs;
  258.  
  259.     /* for every character in the Video RAM, check if it has been modified */
  260.     /* since last time and update it accordingly. */
  261.     for (offs = videoram_size - 2;offs >= 0;offs -= 2)
  262.     {
  263.         if (dirtybuffer[offs] || dirtybuffer[offs + 1])
  264.         {
  265.             int sx,sy;
  266.             int flipx,flipy;
  267.  
  268.             dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
  269.  
  270.             sx = (offs/2) % 32;
  271.             sy = (offs/2) / 32;
  272.             flipx = videoram[offs + 1] & 0x04;
  273.             flipy = videoram[offs + 1] & 0x08;
  274.  
  275.             if (flipscreen)
  276.             {
  277.                 flipx = !flipx;
  278.                 flipy = !flipy;
  279.  
  280.                 sx = 31 - sx;
  281.                 sy = 31 - sy;
  282.             }
  283.  
  284.             drawgfx(tmpbitmap,Machine->gfx[0],
  285.                     videoram[offs] + ((videoram[offs + 1] & 0x03) << 8),
  286.                     palette_bank,
  287.                     flipx,flipy,
  288.                     8*sx,8*sy,
  289.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  290.         }
  291.     }
  292.  
  293.     /* copy the character mapped graphics */
  294.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  295.  
  296.     /* draw the balls */
  297.     drawgfx(bitmap,Machine->gfx[2],
  298.             ball1_pic,
  299.             palette_bank,
  300.             0,0,
  301.             xld1,yld1,
  302.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  303.  
  304.     drawgfx(bitmap,Machine->gfx[3],
  305.             ball2_pic,
  306.             palette_bank,
  307.             0,0,
  308.             xld2,yld2,
  309.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  310.  
  311.     /* draw the crow */
  312.     drawgfx(bitmap,Machine->gfx[1],
  313.             crow_pic,
  314.             palette_bank,
  315.             crow_flip,crow_flip,
  316.             crow_flip ? xld3-16 : 256-xld3, crow_flip ? yld3-16 : 256-yld3,
  317.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  318. }
  319.